package com.fh.util;

import java.io.File;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.multipart.MultipartFile;

public class UploadDiy {
	
	public static int uploadPic(String produceid, MultipartFile f, HttpServletRequest request){
		int state=0;
		String webParentPath = new File(request.getSession().getServletContext().getRealPath("/")).getParent();// 当前WEB环境的上层目录
		String realPath = webParentPath + "/upload/" + produceid;// 文件上传到服务器的真实路径
		
		File pathFile = new File(realPath);
		if (!pathFile.exists()) {
			//文件夹不存 创建文件
			pathFile.mkdirs();
		}
		//将文件copy上传到服务器
		String oldPath=realPath + "/" + f.getOriginalFilename();
		String newPath=request.getSession().getServletContext().getRealPath("/photo")+"/"+ produceid+ "/" + f.getOriginalFilename();
		try {
			f.transferTo(new File(oldPath));
			copyFile(oldPath, newPath);
			state = 0;
		} catch (Exception e) {
			e.printStackTrace();
			state = 1;
		}
		return state;
	}
	
	public static int uploadVoice(MultipartFile f, HttpServletRequest request){
		return 1;
	}
	
	public static int uploadVideo(MultipartFile f, HttpServletRequest request){
		return 1;
	}
	
	public static void copyFile(String Oldpath,String path){
		
	}
}
